﻿Option Strict On
Option Explicit On

''' <summary>
''' Tracks and provides access to the game execution time.
''' </summary>
''' <remarks></remarks>
Public Structure GameTime
    Private _LastFrame As Single
    ''' <summary>
    ''' The fractional number of seconds elapsed during the last frame. This value is often used
    ''' to time update logic in operations-per-second by multiplying a target value by LastFrame.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The fractional duration in seconds of the last frame.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property LastFrame As Single
        Get
            Return _LastFrame
        End Get
    End Property

    ''' <summary>
    ''' The amount of real-word time which has elapsed since the GameEngine started.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The total number of real-world seconds elapsed.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property SecondsElapsedTotal As Single
        Get
            Dim instant As DateTime = DateTime.Now
            Return CSng(instant.Subtract(_StartTime).TotalSeconds)
        End Get
    End Property

    Private _SecondsElapsed As Single
    ''' <summary>
    ''' The amount of game-time which has elapsed since the GameEngine started.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The total number of game-time seconds elapsed.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property SecondsElapsed As Single
        Get
            Return _SecondsElapsed
        End Get
    End Property

    Private _StartTime As DateTime
    ''' <summary>
    ''' The time at which the game started.
    ''' </summary>
    ''' <value></value>
    ''' <returns>The date and time when the GameEngine started.</returns>
    ''' <remarks></remarks>
    Public ReadOnly Property StartTime As DateTime
        Get
            Return _StartTime
        End Get
    End Property

    Friend Sub Start()
        _StartTime = DateTime.Now
        _SecondsElapsed = Geometry.ZERO
        _LastFrame = Geometry.ZERO
    End Sub

    Friend Sub Update(ByVal elapsedTime As Single)
        _SecondsElapsed += elapsedTime
        _LastFrame = elapsedTime
    End Sub
End Structure
